/*
 * @Author: 熊燕萍
 * @Date: 2021-10-11 10:00:38
 * @LastEditors: 熊燕萍
 * @LastEditTime: 2021-10-22 16:31:35
 * @Description: 
 * @FilePath: \ys.ezdz\src\ys\map\polyline.js
 */
import Feature from 'ol/Feature';
import LineString from 'ol/geom/LineString';
import Style from 'ol/style/Style';
import Stroke from 'ol/style/Stroke';

function Polyline(map){
  this.map = map;
}

/**
 * @description: 添加线
 * @param {*} data 线坐标
 * @param {*} layer 图层对象
 * @param {*} styleObj 样式对象 {strokeColor:'',strokeWidth:''}
 * @return {*}
 */
Polyline.prototype.addPolyline = function(data,layer,styleObj){
  let polylineLayer = layer;
  //实例化Vector要素，通过矢量图层添加到地图容器中
  let feature = new Feature({
    geometry: new LineString(data,'XY')
    //标注信息
    // markerInfo: markerInfo||''
  });
  feature.setStyle(styleFunction(styleObj));
  let source = polylineLayer.getSource();
  source.addFeature(feature);
}
let styleFunction = function(styleObj) {
  const style = new Style({
    stroke: new Stroke({
      color: styleObj.strokeColor||'#FFFFFF',
      width: styleObj.strokeWidth||2,
      //lineDash:[1,2,3,4,5,6]
    })
  });
  return style;
};
export default Polyline
